﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Script.Services;

namespace ASP.NET_WSdemo
{
    /// <summary>
    /// Summary description for CustomerServices
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
    [System.Web.Script.Services.ScriptService]
    public class CustomerServices : System.Web.Services.WebService
    {

        [WebMethod]
        [ScriptMethod(ResponseFormat=ResponseFormat.Json,UseHttpGet=true)]
        public List<Models.Customer> getCustomerList()
        {
            List<Models.Customer> customerList = new List<Models.Customer>();
            for (int idx = 0; idx < 10; idx++)
            {
                Models.Customer customer = new Models.Customer();
                customer.id = idx;
                customer.Name = "CustomerName" + idx.ToString();
                customer.Surname = "CustomerSurname" + idx.ToString();
                customer.Address = "CustomerStreet" + idx.ToString();
                customer.ordersList = new List<Models.Order>();
                customerList.Add(customer);
            }
            return customerList;
        }

        [WebMethod]
        [ScriptMethod(ResponseFormat = ResponseFormat.Json, UseHttpGet = true)]
        public Models.Customer getCustomer(int id)
        {
            Models.Customer customer = new Models.Customer();
            customer.id = id;
            customer.Name = "CustomerName" + id.ToString();
            customer.Surname = "CustomerSurname" + id.ToString();
            customer.Address = "CustomerStreet" + id.ToString();
            customer.ordersList = new List<Models.Order>();
            for (int i = 0; i < 5; i++)
            {
                customer.ordersList.Add(new Models.Order() { date = DateTime.Now.ToShortDateString(), number = Guid.NewGuid().ToString() });
            }
            return customer;
        }
        [WebMethod]
        [ScriptMethod]
        public Models.Customer SaveCustomer(Models.Customer customer)
        {

            customer.Name += "Just Saved";
            return customer;
        }
    }
}
